package org.paradise.dms.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.log4j.Logger;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.paradise.dms.pojo.Apartment;
import org.paradise.dms.pojo.Hall;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.BaseHibernateDao;
import com.dheaven.framework.dao.DaoException;

@Service
public class HallDAOImpl extends BaseHibernateDao<Hall> {
	private static Logger log = Logger.getLogger(HallDAOImpl.class);
	@Autowired
	private StudentBedLinkDAOImpl studentbedlinkDAOImpl;
	
	public List getAllPersonInHall(){
		SQLQuery q = this.getSession().createSQLQuery("select h.hallid,s.studentid,s.studentno,s.studentname from hall h,student s where h.studentid=s.studentid");
		return q.list();
	}
	public int deleteHallItem(int hallId){
		 SQLQuery q = this.getSession().createSQLQuery("delete from hall where studentid = ?");
		 q.setInteger(0, hallId);
		 return q.executeUpdate();
	}
	public String intoHall(int studentid){
		try {
			studentbedlinkDAOImpl.deleteStudentBedLink(studentid);
		} catch (DaoException e) {
			e.printStackTrace();
			return "移入大厅失败";
		}
		SQLQuery q = this.getSession().createSQLQuery("insert into hall(studentid) values (?)");
		q.setInteger(0, studentid);
		if(q.executeUpdate() > 0){
			return "移入大厅成功";
		}else{
			return "移入大厅失败";
		}
		
	}
	
}
